package cmsoa.action.system;



import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import cmsoa.db.DBUtil;
import cmsoa.db.pojo.TXtUser;
import cmsoa.helper.RequestHelper;

import com.opensymphony.xwork2.Action;

public class UserAction {
	private static final Logger log = Logger.getLogger(UserAction.class);
	private TXtUser user;
	private Map lastLogin;
	private List<Map> users;
	private List<String> errors = new ArrayList();
	
	public String userSessionMsg(){
		Object obj = RequestHelper.getSession().getAttribute("user");
		if(obj != null){
			this.lastLogin = (Map)RequestHelper.getSession().getAttribute("user_lastLogin");
			this.user = (TXtUser)obj;
			if(lastLogin==null){
				lastLogin = new HashMap(1);
			}
		}
		return Action.SUCCESS;
	}
	
	/**
	 * 查询数据库用户信息
	 * @param uid
	 * @param db
	 */
	public static TXtUser queryUser(String uid, DBUtil db){
		Map params = new HashMap(1);
		params.put("UId", uid);
		List<TXtUser> list = db.queryByPojo(TXtUser.class, params);
		return list.size()>0?list.get(0):null;
	}
	
	public String save(){
		return Action.SUCCESS;
	}
	
	public String delete(){
		return Action.SUCCESS;
	}
	
	public String queryAll(){
		StringBuffer sql = new StringBuffer("select * from T_XT_USER ");
		DBUtil db = DBUtil.getDBUtilByRequest();
		List<Map> params = new ArrayList(2);
		return Action.SUCCESS;
	}
	
	public TXtUser getUser() {
		return user;
	}

	public void setUser(TXtUser user) {
		this.user = user;
	}

	public List<Map> getUsers() {
		return users;
	}

	public void setUsers(List<Map> users) {
		this.users = users;
	}

	public Map getLastLogin() {
		return lastLogin;
	}

	public List<String> getErrors() {
		return errors;
	}
}
